/********************************************************************************************
 * Copyright 2011, zhaosting <zhaosting@gmail.com>
 *
 * This file is part of QPcxPlugIn.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 *******************************************************************************************/

#include "qpcxplugin.h"
#include "qpcxhandler.h"
#include <QtGui>


QStringList QPcxPlugin::keys() const
{
    return QStringList() << "pcx" << "PCX";
}

QImageIOPlugin::Capabilities QPcxPlugin::capabilities(QIODevice *device,const QByteArray &format) const
{
    if(format == "pcx")
    {
        qDebug() << "CanRead";
        return CanRead | CanWrite;
    }
    if(format.isEmpty())
    {
        QPcxHandler handler;
        handler.setDevice(device);
        if(handler.canRead())
        {
            return CanRead | CanWrite;
        }
    }
    return 0;
}

QImageIOHandler *QPcxPlugin::create(QIODevice * device,
                                      const QByteArray &format) const
{
    QPcxHandler *handler = new QPcxHandler;
    handler->setDevice(device);
    handler->setFormat(format);
    qDebug() << "the size is:" << device->size();
    return handler;
}

Q_EXPORT_PLUGIN2(QPcxPlugin,QPcxPlugin)
